package org.viettan.android.main.model;

import org.viettan.android.main.io.UrlUtility;

import android.net.Uri;

import com.google.common.base.Preconditions;

/**
 * Represents a single article as it appears on the Viet Tan website.
 */
@SuppressWarnings("serial")
public class Article implements Entity {
    private int id;
    private int imageResourceId;
    private String title;
    private String intro;
    private String body;
    private String author;
    private Uri imageSmallUrl;
    private Uri imageLargeUrl;
    private Uri articleWebUrl;
    private int sectionId;

    public Article() {
    }

    /**
     * Sets the ID of the article.
     *
     * @param id
     * @return
     */
    public Article setId(int id) {
	Preconditions.checkArgument(id > 0, "Id must be positive");

	this.id = id;
	return this;
    }

    /**
     * Returns the ID of the article.
     */
    public int getId() {
	return id;
    }

    /**
     * Sets the section ID of the article.
     *
     * @param sectionDd
     * @return
     */
    public Article setSectionId(int sectionId) {
	Preconditions.checkArgument(sectionId > 0, "Section Id must be positive");

	this.sectionId = sectionId;
	return this;
    }

    /**
     * Returns the Section ID of the article.
     */
    public int getSectionId() {
	return sectionId;
    }

    /**
     * Sets the title of the article.
     *
     * @param title
     * @return
     */
    public Article setTitle(String title) {
	this.title = title;
	return this;
    }

    /**
     * Returns the title of the article.
     */
    public String getTitle() {
	return title;
    }

    /**
     * Sets the first few sentences of the article.
     *
     * @param intro
     * @return
     */
    public Article setIntro(String intro) {
	this.intro = intro;
	return this;
    }

    /**
     * Returns the first few sentences of the article.
     */
    public String getIntro() {
	return intro;
    }

    /**
     * Sets the URL to the small image of this article.
     *
     * @param imageSmallUrl
     * @return
     */
    public Article setTitle(Uri imageSmallUrl) {
	this.imageSmallUrl = imageSmallUrl;
	return this;
    }

    /**
     * Sets the URL to the small image of this article.
     *
     * @param imageSmallUrl
     * @return
     */
    public Article setImageSmallUrl(Uri imageSmallUrl) {
	this.imageSmallUrl = imageSmallUrl;
	return this;
    }

    /**
     * Returns the URL to the small image of this article.
     */
    public Uri getImageSmallUrl() {
	return imageSmallUrl;
    }

    /**
     * Sets the URL to the large image of this article.
     *
     * @param imageLargeUrl
     * @return
     */
    public Article setImageLargeUrl(Uri imageLargeUrl) {
	this.imageLargeUrl = imageLargeUrl;
	return this;
    }

    /**
     * Returns the URL to the large image of this article.
     */
    public Uri getImageLargeUrl() {
	return imageLargeUrl;
    }

    /**
     * Sets the full HTML text of the article.
     *
     * @param body
     * @return
     */
    public Article setBody(String body) {
	this.body = body;
	return this;
    }

    /**
     * Returns the full HTML text of the article.
     */
    public String getBody() {
	return body;
    }

    /**
     * Sets the URL of the article on the website.
     */
    public Article setArticleWebUrl(Uri articleWebUrl) {
	this.articleWebUrl = articleWebUrl;
	return this;
    }

    /**
     * Returns the URL of the article on the website.
     */
    public Uri getArticleWebUrl() {
	return articleWebUrl;
    }

    /**
     * Sets the author of the article.
     *
     * @param author
     */
    public Article setAuthor(String author) {
	this.author = author;
	return this;
    }

    /**
     * Returns the author of the article.
     */
    public String getAuthor() {
	return author;
    }

    /**
     * Returns the URL of the article XML source.
     */
    public Uri getArticleXmlUrl() {
	return UrlUtility.getArticleXmlUrl(id);
    }

    /**
     * Sets the resource ID of the local image to be displayed.
     *
     * @param imageResourceId
     *            resource ID of the local image
     */
    public Article setImageResourceId(int imageResourceId) {
	this.imageResourceId = imageResourceId;
	return this;
    }

    /**
     * Returns the resource ID of the local image to be displayed. This might be 0.
     *
     * @return resource ID of the image or 0.
     */
    public int getImageResourceId() {
	return imageResourceId;
    }

    @Override
    public String toString() {
	return title;
    }
}


